<%@page import="java.sql.*"%>
<%@page import="com.mysql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration</title>
</head>
<style type="text/css">
textarea{ resize: none;
		  
}
</style>
<body>
<%
    try{
    	
    	String movie = "Airheads";
    	String user = "kyleb";
    	int i = 4;
    	
    	String searchFor = request.getParameter("searchBox");

    	
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = 
         DriverManager.getConnection
            ("jdbc:mysql://localhost:3306/moviedatabase","dbuser","dbpassword");

       Statement statement4 = connection.createStatement() ;
       Statement statement6 = connection.createStatement() ;
       Statement statement5 = connection.createStatement();
       
       ResultSet rs4 = statement4.executeQuery("select * from movies WHERE Title='"+movie+"'") ;
       
       ResultSet rs5 = statement6.executeQuery("select * from users WHERE _y4 ='"+user+"'") ;
    
       ResultSet rs3 = 
           statement5.executeQuery("SELECT MAX(queue.Position) as Maxp From queue INNER JOIN users ON queue.UserID = users._z4 WHERE users._z4 ="+i); 
       
       String s = null;
        while(rs3.next()){ 
       s = rs3.getString(1);
      }
       
       int f = Integer.parseInt(s);
       f++;
       Integer.toString(f);
       

   
%>    
<center>
    <h1>-----------------------</h1>
     
   
        <div align="center">
        <form:form action="addtoqueue" method="post" commandName="queueForm">
            <table border="0">
                <tr>
                    <td colspan="2" align="center"><h2>This is a movie page</h2></td>
                </tr>
                <% while(rs4.next()){ %>
                <tr>
                    <td>MovieID: </td>
                    <td><form:input path="movieID" value="<%=rs4.getString(1)%>" readonly="true"/></td>
                </tr>
                  <% } %>
                     <% while(rs5.next()){ %>
                <tr>
                    <td>UserID: </td>
                    <td><form:input path="userID" value="<%=rs5.getString(1)%>" readonly="true"/></td>
                  
                </tr>
                 <% } %>
                
                <tr>
                    <td>Position: </td>
                    <td><form:input path="position" value="<%=f%>" readonly="true"/></td>
                </tr>
              
                <tr>
                    <td colspan="2" align="center"><input type="submit" value="Add to Queue"/></td>
                </tr>
              
            </table>
        </form:form>
    </div>
</center>

<%
//**Should I input the codes here?**
        }
        catch(Exception e)
        {
             out.println("wrong entry"+e);
        }
%>
    
</body>
</html>